#! /usr/bin/env python
# -*- coding: utf-8 -*-
# vim:fenc=utf-8
#
# Copyright © 2018 crane <crane@his-pc>
#
# Distributed under terms of the MIT license.

"""

"""


class ListNode(object):
    def __init__(self, val, next=None):
        self.val = val
        self.next = next


class Solution:
    def deleteDuplicates(self, head):
        # head 可能改变, 所以需要dummy_head
        dummy_head = ListNode('dummy', head)

        pre = dummy_head
        next = head

        # 循环一致性: pre 和 next一定不同
        while pre and next and next.next:
            if next.val != next.next.val:
                pre = next
                next = next.next
                continue

            # 相同则顺next.next摸瓜
            val = next.val
            may_same = next.next.next
            while may_same:
                if may_same.val != val:
                    break
                may_same = may_same.next
            pre.next = may_same
            next = may_same

        return dummy_head.next


def main():
    print("start main")

if __name__ == "__main__":
    main()
